﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MailMergeReplaceAspose.Helper
{
    public class FastHelper
    {
        public static List<string> GenCase(string input)
        { 
            
            if (String.IsNullOrWhiteSpace(input) )
                return new List<string>();
            String[] listofInput = input.Split('-');
            Array.Sort(listofInput,StringComparer.InvariantCulture);
            if (listofInput.Length <= 1)
                return new List<string>();
            List<string> result =  new List<string>();
           // result.AddRange(listofInput);
            string daygop = "";
            bool isEquals = false;
            int totalDay = 0;
            int startday = 0, endday = 0;
            for (int index = 1; index < listofInput.Length;index++ )
            {
                // nhom cac day
               
                totalDay = (listofInput.Length/index);
                for(int indexdayso = 1; indexdayso <= totalDay;indexdayso+=index )
                {
                    // gop day
                    daygop = "";
                    startday = indexdayso;
                    endday = totalDay%indexdayso;
                    endday = (endday == 0)? totalDay/indexdayso:endday;
                    for (int indexgopday = startday; indexgopday < endday; indexgopday++)
                    {
                        daygop += listofInput[startday + indexgopday] + '-';
                    }
                    if (daygop.LastIndexOf('-') == daygop.Length - 1)
                        daygop = daygop.Substring(0, daygop.Length - 1);
                    // kiem tra trung day
                    foreach (var item in result)
                    {
                        if (FastHelper.ComparerOrder(daygop, item))
                            isEquals = true;
                    }
                    if(!isEquals )
                        result.Add(daygop);
                }
            }
            return result;
        }
        public  static bool ComparerOrder (string input,string destination)
        {
            String[] listofInput = input.Split('-'),listofDestination = destination.Split('-');
            Array.Sort(listofInput,StringComparer.InvariantCulture);
            Array.Sort(listofDestination,StringComparer.InvariantCulture);
            return listofDestination.All(itemdes => listofInput.All(itemin => itemdes != itemin));
        }

    }
}